Ext.define('PJ.view.myPersonalFiles.LookPxarchives', {
	extend: 'AM.default.DefaultWindowForm',
	alias: ['widget.trainingManagementEdit'],
	requires: ['AM.default.DefaultDateField', 
	           'AM.default.DateTime',
	           'AM.default.jsonp.DefaultSubmitJsonp',
	           'AM.default.DefaultDateField'
	           ],
	modal: true,// 开启不允许点击其他组件
	frame: true,
	notEdit: true,
	width: 650,
	height:365,
	layout: 'form',
	isSame: false,
	overflowY:'auto',
	autoScroll:false,
	initComponent: function(){
    	var me = this;
    	var bt = '<span style="color:red;">*</span>';
    	if(me.flag == 4 ){
    		bt = "";
    	}
        var theDate = new Date();
        theDate.setFullYear(theDate.getFullYear() + 1, 0, 1);
    	me.items= [{
    		defaults: {
    			labelAlign: 'right',
    			labelWidth: 90,
    			columnWidth: .5,
    			padding:"9 0 0 0",
    			readOnly:me.isView
    		},
    		border: false,
    		xtype: "container",
    		width: 610,
    		height:300,
    		layout: 'column',
    		allowBlank: false,
    		items: [{
            	xtype: 'textfield',
            	fieldLabel: '年度',
    			readOnly:true,
                name: 'classnameYear'
            },{
            	xtype: 'textfield',
            	fieldLabel: '离岗状态',
    			readOnly:true,
                name: 'beoffStation'
            },{
    			xtype: 'textfield',
    			fieldLabel:me.flag==3?'培训班名称': bt+'培训班名称',
    			disabled:me.flag==3?true:false,
    			name: 'className',
    			allowBlank: me.isReadOnly,
    			readOnly:true,
                listeners: {
                	change: function(textField){
                		if(textField.getValue() && textField.getValue().length > 50){
                			Orchid.alert('提示','该输入项最多输入50个字符！');
                		}
                	}
                },
    			columnWidth:1,
                maxLength: 50
    		},{
            	xtype: 'textfield',
            	fieldLabel: bt + '培训班类型',
    			readOnly:true,
                name: 'classTypeStr'
            },{
            	xtype: 'textfield',
            	fieldLabel: bt + '培训类别',
    			readOnly:true,
                name: 'categoryId'
            },{
				xtype: 'defaultDate',
				fieldLabel:bt+'开班时间',
    			readOnly:true,
    			allowBlank: me.isReadOnly,
				name: 'beginDateStr'
			},
			{
				xtype: 'defaultDate',
				fieldLabel: bt+'结业时间',
    			readOnly:true,
    			allowBlank: me.isReadOnly,
				name: 'endDateStr'
			},{
    			xtype: 'numberfield',
    			fieldLabel: bt+'学时',
    			readOnly:true,
    			name: 'trainingHour'
    		},{
    			xtype: 'textfield',
    			fieldLabel: bt + '天数',
    			readOnly:true,
    			name: 'days'
    		},{
    			xtype: 'textfield',
    			fieldLabel:me.flag==3?'主办单位':bt+'主办单位',
    			name: 'sponsorName',
    			allowBlank: true,
    			readOnly:true,
    			margin: "5 0 0 0",
    			value: '中共北京市委组织部',
    			disabled:me.flag==3?true:false,
    			columnWidth: 1
    		},/*{
    			xtype: "button",
    			columnWidth:.06,
    			tooltip: '合办单位',
    			margin: "9 0 0 5",
    			padding: "3 0 3 3",
    			editable: false,
    			disabled:me.flag==3?true:false,
    			readOnly:true,
    			iconCls:"configIco",
    			hidden:me.isReadOnly,
    			handler: function(button){
    				var  baseForm = this.up('form').getForm();
    				var scopeDepartmentNames = baseForm.findField('scopeDepartmentNames');
    				var scopeDepartmentIds = baseForm.findField('scopeDepartmentIds');
    				Ext.create("PJ.view.trainingmanagement.WindowFrame", {
                        title: "选取合办单位",
                        edit:this,
                        scopeDepartmentNames:scopeDepartmentNames,
                        scopeDepartmentIds:scopeDepartmentIds
                    }).show();
    			}
    		},{
    			xtype: "button",
    			columnWidth:.06,
    			tooltip: '清除',
    			margin: "9 0 0 5",
    			padding: "3 0 3 3",
    			editable: false,
    			disabled:me.flag==3?true:false,
    			iconCls:"deleteIco",
    			hidden:me.isReadOnly,
    			//disabled: me.isReadOnly,
    			handler: function(button){
    				var form = button.up("form");
    				var baseForm = form.getForm();
    				baseForm.findField("scopeDepartmentNames").setValue("");
    				baseForm.findField("scopeDepartmentIds").setValue("");
    			}
    		},*/{
            	xtype: 'textfield',
            	fieldLabel: '培训机构',
    			readOnly:true,
                name: 'trainingDeptId'
            },{
    			xtype: 'textfield',
    			fieldLabel: '培训机构名称',
    			readOnly:true,
    			name: 'trainingDeptName',
                maxLength: 50
    		},{
    			xtype: 'textfield',
    			fieldLabel: '承办单位',
    			name: 'scopeDepartmentNames',
    			allowBlank: true,
    			readOnly:true,
    			disabled:me.flag==3?true:false,
    			columnWidth:me.isReadOnly ? .5 : .38,
    			columnWidth: 1
    		},{
    			xtype: 'hidden',
    			name: 'classId'//培训班Id
    		},{
    			xtype: 'hidden',//培训班编号
    			name: 'classNum'
    		}]
    	}/*,{
    		xtype: "container",
			layout: 'column',
			defaults: {
    			labelAlign: 'right',
    			labelWidth: 90,
    			columnWidth: .5,
    			padding:"9 0 0 0",
    			readOnly:me.isView
    		},
			items: [{
				xtype: 'pfCourseList',
				columnWidth: .98,
				hidden:me.flag==4?false:true,
				classId: me.classId,
				padding: '0 0 0 0',
				height: 271
			}]
		}*/];
		this.buttons = [{
			text:"确定",
			scope:this,
			hidden:me.isReadOnly,
			handler:function(btn){
				var win = me;
				var form = win.down('form');
				var baseForm = form.getForm();
				var classNum_ = baseForm.findField("classNum_");
				if(classNum_ != null && classNum_.getValue() != null && classNum_ != ""){
					baseForm.findField("classNum").setValue(classNum_.getValue());
				}
				if (!baseForm.isValid()) {
					return;
				}
				var url = "";
				var params = {};
				if(me.flag==1){				//1 新增  2 修改   3 完善
					url = me.grid.store.addUrl;
				}else if(me.flag==2){
					url = me.grid.store.updateUrl;
				}else if(me.flag==3){
					url = me.grid.store.derfectUrl;
					params = {
						className: win.className,
						ministrieName: win.ministrieName
					};
				}
				
				if(gj_onlineLearning_constant.loadType == "jsonp"){
					baseForm.doAction('submitJsonp',{
						submitEmptyText: false,//忽略emptyValue
						url: url,
						params: params,
						success: function(f, action){
							if (action.result.success) {
								Orchid.alert('消息', "操作成功!", function(){
									var gridPanel = win.grid;
									var store = gridPanel.getStore();
									store.reload();
									win.close();
								});
							}else{
								Orchid.alert('消息', action.result.msg||"系统出错,请联系管理员!", function(){
									win.close();
								});
							}
						},
						failure: function(f, action){
							Orchid.alert('错误', action.result.msg||"系统出错,请联系管理员!");
						}
					});
				}else{
					form.submit({
						submitEmptyText: false,//忽略emptyValue
						url: url,
						params: params,
						success: function(f, action){
							if (action.result.success) {
								Orchid.alert('消息', "操作成功!", function(){
									var gridPanel = win.grid;
									var store = gridPanel.getStore();
									store.reload();
									win.close();
								});
							}else{
								Orchid.alert('消息', action.result.msg||"系统出错,请联系管理员!", function(){
									win.close();
								});
							}
						},
						failure: function(f, action){
							Orchid.alert('错误', action.result.msg||"系统出错,请联系管理员!");
						}
					});
				}
			}
		},{
			text: '关闭',
			scope: this,
			hidden:me.isReadOnly,
			handler: this.close
		},{
			text: '关闭',
			scope: this,
			hidden:!me.isReadOnly,
			handler: this.close
		}];
		this.callParent(arguments);
	}
});